/**
 * 画右上角的趋势图，暂时画一天的平均数据，以后可能改成一个月或者一年
 * @param categoriesarray	表示波长从200到708左右
 * @param hg_wid	表示该图的宽度
 */
function initTendencyGraph(){
	
	//TODO 假设日期是这个月
	var month = "2014-11";
	
	var datas;
	var monthStr;
	//用ajax获取一个月平均数据
	$.ajax({
        type: "post",
        async: false, 
        url: $('#basePath').val()+"getMonthAvgIsaData",
        data: {
        	"month":month
        },
        success:function(data,status) {
        	
        	if(data==""){
        		//TODO 右上角的趋势图没有数据时的提醒
        		//alert("没有上个月份的数据");
        		return;
        	}
        	isas = JSON.parse(data); //得到数组
        	
        	for(i=0;i<isas.length;i++){
        		if(isas[i].mode==0){
        			datas = isas[i].avgValues;
        			monthStr = isas[i].monthStr;
        		}
        	}
        },
        error:function(data,status){
        	alert("ajax error.");
        }
     });
	
	//下面是绘图
	$('#tendency_hchart').highcharts({
    	chart:{
    		width:small_hg_wid,
    		height:230
    	},
    	credits:{
    		enabled:false,
    	},
        title: {
            text: monthStr,
            x: -20 //center
        },
        xAxis: {
            categories: categoriesarray
        },
        yAxis: {
            title: {
                text: 'Absorbance'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: ''
        },
        
        legend: {
        	enabled:false,
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [{
            data: datas,
            name: "value",
            zIndex: -1,
            events: {  
                click: function(e) {  
                    alert(e.point.category);
                }  
            }  
        }]
    });
}


/**动态调整高度,显示一定时间间隔的Isa数据头像*/
function drawIntervalIsaChart(mode0data){
	
	var recordNum = mode0data.length;
//	var line;
//	if(recordNum%3==0){
//		line = recordNum/3;
//	}else{
//		line = recordNum/3+1;
//	}
//	var height = 300+18*line;	//图像固定为300px,18为一行legend的高度
	
	var height = 400;
	
	$('#big_hg').highcharts({
    	
    	chart:{
    		width:big_hg_wid,
    		height:height
    	},
    	credits:{
    		enabled:false,
    	},
        title: {
            text: "Absorptivity",
            x: -20 //center
        },
        xAxis: {
            categories: categoriesarray,
        },
        yAxis: {
            title: {
                text: 'absorption'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: ''
        },
        legend: {
            layout: 'horizontal',
            align: 'center',
            maxHeight:80,
            verticalAlign: 'bottom',
            borderWidth: 0
        },
        series: mode0data
    });
}

/**左下角图像默认显示的是昨天的数据*/
function drawLastDayGraph(){
	//TODO 假设日期是这天
	var day = "2014-11-19";
	
	var datas;
	var dayStr;
	
	//用ajax获取一个天平均数据
	$.ajax({
        type: "post",
        async: false, 
        url: $('#basePath').val()+"getDayAvgIsaData",
        data: {
        	"day":day
        },
        success:function(data,status) {
        	
        	if(data==""){
        		showErrMsg("dateErrSpan","没有此时间段的数据");
        		return;
        	}
        	isas = JSON.parse(data); //得到数组
        	
        	for(i=0;i<isas.length;i++){
        		if(isas[i].mode==0){
        			datas = isas[i].avgValues;
        			dayStr = isas[i].dayStr;
        		}
        	}
        },
        error:function(data,status){
        	alert("ajax error.");
        }
     });

	//默认显示的图
	$('#big_hg').highcharts({
    	chart:{
    		width:big_hg_wid,
    		height:300
    	},
    	credits:{
    		enabled:false,
    	},
        title: {
            text: dayStr,
            x: -20 //center
        },
        xAxis: {
            categories: categoriesarray,
            gridLineWidth:1
        },
        yAxis: {
            title: {
                text: 'Absorbance'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: ''
        },
        plotOptions: {
            area: {
                fillColor: {
                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
                    stops: [
                        [0, Highcharts.getOptions().colors[0]],
                        [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
                    ]
                },
                lineWidth: 1,
                marker: {
                    enabled: false
                },
                shadow: false,
                states: {
                    hover: {
                        lineWidth: 1
                    }
                },
                threshold: null
            }
        },
        legend: {
            layout: 'vertical',
            align: 'center',
            verticalAlign: 'bottom',
            borderWidth: 0
        },
        series: [{
        	type:"area",
            data: datas,
            name: "yesterday",
            zIndex: -1,
            events: {  
                click: function(e) {  
                    alert(e.point.category);  
                }  
            }  
        }]
    });
}